<?php
$oCnd = new Cnd_Model();

/*
 * 
 * GERA GRÁRFICOS específicos de linha e total
 * 
 * 
 */


$totalRfb = $oCnd->qtdTodosTipo(1)->total;
$totalCrf = $oCnd->qtdTodosTipo(2)->total;

$totalEstadual30 = $oCnd->qtdTodosAmbitoDias(2, 30)->total;
$totalEstadual60 = $oCnd->qtdTodosAmbitoDias(2, 60)->total;
$totalEstadual180 = $oCnd->qtdTodosAmbitoDias(2, 180)->total;

$totalMunicipal30 = $oCnd->qtdTodosAmbitoDias(3, 30)->total;
$totalMunicipal90 = $oCnd->qtdTodosAmbitoDias(3, 90)->total;
$totalMunicipal180 = $oCnd->qtdTodosAmbitoDias(3, 180)->total;


/*
 * 
 * GERA GRÁRFICOS específicos de linha e total
 * 
 * 
 */



$totalAmbito1 = $oCnd->qtdTodosAmbitoGeral(1, 1)->total;
$totalAmbito2 = $oCnd->qtdTodosAmbitoGeral(1, 2)->total;




/*
 * 
 * GERA GRÁRFICOS total combo
 * 
 * 
 */



/*
 * 
 * GERA GRÁRFICOS total combo
 * 
 * 
 */

if (isset($_GET['empresa'])) {
    $empresa = $_GET['empresa'];
} else {
    $empresa = "";
}
if (isset($_GET['ambito'])) {
    $ambito = $_GET['ambito'];
} else {
    $ambito = "";
}
if (isset($_GET['orgao'])) {
    $orgao = $_GET['orgao'];
} else {
    $orgao = "";
}

$documentosVencida = $oCnd->qtdTodosEmDia($empresa, $ambito, $orgao)->total;
$documentosEmdia = $oCnd->qtdTodosVencida($empresa, $ambito, $orgao)->total;





$documentosQuantidade = $oCnd->documentosQuantidade();





/*
 * 
 * GERA GRÁRFICOS com filtros
 * 
 * 
 */



/*
 * 
 * GERA GRÁRFICOS com filtros
 * 
 * 
 */
?>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>

<script type="text/javascript">


    google.load("visualization", "1", {packages: ["corechart"]});

    google.setOnLoadCallback(drawVisualization);
//google.setOnLoadCallback(geraGrafico2);

    function drawVisualization() {
// Some raw data (not necessarily accurate)
        var data = google.visualization.arrayToDataTable([
            ['Certidões', 'Em Dia', 'Vencidas', 'Total'],
            ['Nacional', <?php echo $ambito1 = $oCnd->qtdTodosAmbitoGeral(1, 1)->total; ?>, <?php echo $ambito1V = $oCnd->qtdTodosAmbitoGeral(1, 2)->total; ?>, <?php echo $ambito1 + $ambito1V; ?>],
            ['Estadual', <?php echo $ambito2 = $oCnd->qtdTodosAmbitoGeral(2, 1)->total; ?>, <?php echo $ambito2V = $oCnd->qtdTodosAmbitoGeral(2, 2)->total; ?>, <?php echo $ambito2 + $ambito2V; ?>],
            ['Municipal', <?php echo $ambito3 = $oCnd->qtdTodosAmbitoGeral(3, 1)->total; ?>, <?php echo $ambito3V = $oCnd->qtdTodosAmbitoGeral(3, 2)->total; ?>, <?php echo $ambito3 + $ambito3V; ?>]
        ]);

        var options = {
            title: 'Comparativo de regularidade',
            vAxis: {title: ""},
            hAxis: {title: ""},
            seriesType: "bars",
            series: {5: {type: "line"}}
        };

        var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
        chart.draw(data, options);
    }


    google.load("visualization", "1", {packages: ["corechart"]});

    google.setOnLoadCallback(drawVisualization2);

    function drawVisualization2() {
// Some raw data (not necessarily accurate)
        var data = google.visualization.arrayToDataTable([
            ['Certidões', 'Em Dia', 'Vencidas', 'Total'],
            ['Nacional', 2, 4, 6],
            ['outra', 2, 4, 6],
            ['Estadual', <?php echo $ambito2 = $oCnd->qtdTodosAmbitoGeral(2, 1)->total; ?>, <?php echo $ambito2V = $oCnd->qtdTodosAmbitoGeral(2, 2)->total; ?>, <?php echo $ambito2 + $ambito2V; ?>],
            ['Municipal', <?php echo $ambito3 = $oCnd->qtdTodosAmbitoGeral(3, 1)->total; ?>, <?php echo $ambito3V = $oCnd->qtdTodosAmbitoGeral(3, 2)->total; ?>, <?php echo $ambito3 + $ambito3V; ?>]
        ]);

        var options2 = {
            title: 'Demonstrativo de status',
            vAxis: {title: ""},
            hAxis: {title: ""},
            seriesType: "bars",
            series: {5: {type: "line"}}
        };

        var chart = new google.visualization.ComboChart(document.getElementById('chart_div2'));
        chart.draw(data, options2);
    }


    google.load("visualization", "1", {packages: ["corechart"]});
    google.setOnLoadCallback(drawChart);
    function drawChart() {

        var data = google.visualization.arrayToDataTable([
            ['Task', 'Hours per Day'],
            ['Em dia', <?php echo $documentosVencida ?>],
            ['Vencidas', <?php echo $documentosEmdia ?>]
        ]);

        var options = {
            title: 'Comparativo de validade'

        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
    }



    google.load("visualization", "1", {packages: ["corechart"]});
    google.setOnLoadCallback(drawChart2);
    function drawChart2() {

        var data2 = google.visualization.arrayToDataTable([
            ['Task', 'Hours per Day'],
<?php foreach ($documentosQuantidade as $documento) { ?>
                [ '<?php echo $documento->tipoCnd_descricao ?>', <?php echo $documento->total ?>],
<?php } ?>
        ]);

        var options2 = {
            title: 'Quantitativo de certidões'
        };

        var chart2 = new google.visualization.PieChart(document.getElementById('piechart2'));

        chart2.draw(data2, options2);
    }


</script>
<!--<center>
    <a class="medium" id="botaoModal" style="color: #000; font-size: 25px;" data-reveal-id="CadastrarPencencias" target="_blank" title="Cadastrar Pendências" onclick="" href="">
        <i class="fi-alert medium"></i>
    </a>
</center>-->

<div class="row2" >
    <table border="0" class="table table-bordered"  style="width: 100%; background-color: white;" cellpadding="0" cellspacing="0">
        <thead>
            <tr style="background-color: #ededed">
                <td colspan="2">Produtividade</td>
            </tr>
        </thead>
        <tr>            
            <td>
                <center>
                <div id="piechart2" style="width: 627px; height: 400px;"></div>
                </center>
            </td>            
            <td>
                <center>
                    <div id="chart_div" style="width: 627px; height: 400px;"></div>
                </center>
            </td>            
        </tr>
        <tr>        
            <td style="background-color: white"> 
                <center>
                    <div id="piechart" style="width: 627px; height: 400px;"></div>
                </center>
            </td>                                    
        </tr>
    </table>
</div>
                <!--<form name="formularioBusca" id="formularioBusca" method="get" action="">-->



<!--                    <label>
                        <select name="empresa" id="empresa"  style="width: 440px" >
                            <option  value="">Empresas</option>
                            <?php
//                            $objempresas = new Pessoas_Model();
//                            $empr = $objempresas->getDadosEmpresasGruposUsuario();
//
//                            foreach ($empr as $e) {
                                ?>
                                <option <?php
//                                if ($empresa == $e->pessoas_id) {
//                                    echo "selected='selected'";
//                                }
                                ?> value="<?php // echo $e->pessoas_id ?>"><?php // echo $e->pessoas_razaoSocial ?>
                                </option>
                                <?php
//                            }
                            ?>
                        </select>
                    </label>  -->



<!--                    <label>
                        <select name="uf" id="ambito"  class="ajax-ambito" style="width: 440px">
                            <option  value="">Âmbito</option>
                            <?php
//                            $objAmbito = new Tipocnd_Model();
//                            $ambitos = $objAmbito->getAmbito();
//                            foreach ($ambitos as $ambito) {
                                ?>
                                <option value="<?php // echo $ambito->ambitocnd_id ?>"><?php // echo $ambito->ambitocnd_descricao ?></option>
                            <?php // } ?>
                        </select>                   
                    </label>     -->

<!--
                    <label>
                        <select name="orgao" id="orgao" class="recebe-tipocnd" style="width: 440px">
                            <option  value="">Órgão</option>
                        </select>
                    </label>   

                    <a class="medium" style="color: #000; font-size: 35px; padding-right: 10px; margin-left: 10px;" target="" title="Filtrar" onclick="submitForm()">
                        <i class="fi-magnifying-glass big"></i>
                    </a>-->


                <!--</form>-->

<form name="formulario_certidoes" id="formulario_certidoes" action="" method="post"> 
    <div id="CadastrarPencencias" class="reveal-modal large" data-reveal>            
        <a class="close-reveal-modal">&#215;</a>

        <div class="confirmacao_pendencia">
            <center></center>
        </div>

        <div id="pendencias_view">
            <?php echo $this->load->view('pendencias/relatorios_pendencias_view') ?>
        </div>

    </div>
</form>    


<script>
    document.getElementById("botaoModal").click();

</script>


<script>
    jQuery(function ($) {
        $("#mdata").mask("99/99/9999", {placeholder: " "});
        $("#mdata_validade").mask("99/99/9999", {placeholder: " "});
    });


    $(".ajax-ambito").change(function () {
        var ambtiocnd_id = $(this).val();
        $(".recebe-cidade").html("<option value=''>Aguarde...</option>");
        $.ajax({
            url: '<?php echo base_url('index.php/tipocnd/buscaAmbito') ?>',
            type: 'POST',
            data: {ambtiocnd_id: ambtiocnd_id},
            dataType: 'json',
            success: function (tipocndJson) {
                var txt_tipocnd = "<option value=''>--Selecione o Órgão--</option>";
                $.each(tipocndJson, function (index, tipocnd) {
                    txt_tipocnd += "<option value='" + tipocnd.tipoCnd_id + "'>" + tipocnd.tipoCnd_descricao + "</option>";
                });
                $(".recebe-tipocnd").html(txt_tipocnd);
                $(".recebe-tipocnd").removeAttr("disabled");
            }
        });

    });
</script>

<script>
    function submitForm() {
        document.getElementById("formularioBusca").submit();
    }
</script>